package com.example.service.impl;

import cn.hutool.crypto.SecureUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.common.ResultCode;
import com.example.dao.*;
import com.example.entity.Caizhaiyuyue;
import com.example.exception.CustomException;
import com.example.service.CaizhaiyuyueService;
import com.example.vo.CaizhaiyuyueVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
import java.util.Map;

@Service("caizhaiyuyueService")
public class CaizhaiyuyueServiceImpl extends ServiceImpl<CaizhaiyuyueDao, Caizhaiyuyue> implements CaizhaiyuyueService {

    @Resource
    private CaizhaiyuyueDao caizhaiyuyueDao;

    public Caizhaiyuyue add(Caizhaiyuyue caizhaiyuyue) {
		
	   //youquchong1
        caizhaiyuyue.setAddtime(new Date());
        caizhaiyuyueDao.insert(caizhaiyuyue);
        return caizhaiyuyue;
    }
	
	@Override    public List<Map<String,Object>> caizhaiyuyue_tj_zhongzhiwu() {    List<Map<String,Object>> returnMap = caizhaiyuyueDao.caizhaiyuyue_tj_zhongzhiwu();    return returnMap;    }    
	
    public void delete(Long id) {
        caizhaiyuyueDao.deleteById(id);
    }
	

    public void update(Caizhaiyuyue caizhaiyuyue) {
        //youquchong2
        caizhaiyuyueDao.updateById(caizhaiyuyue);
    }
	
	public void updateByzhujian(Caizhaiyuyue caizhaiyuyue) {
        LambdaQueryWrapper<Caizhaiyuyue> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(ObjectUtils.isNotEmpty(caizhaiyuyue.getYonghuming()), Caizhaiyuyue::getYonghuming,caizhaiyuyue.getYonghuming());

        caizhaiyuyueDao.update(caizhaiyuyue, wrapper);
    }
	
	@Override
    public List<Map<String, Object>> daochuexcel() {
        return caizhaiyuyueDao.daochuexcel();
    }

    @Override
    public Caizhaiyuyue findById(Integer id) {
        return caizhaiyuyueDao.selectById(id);
    }
	
	@Override
    public Caizhaiyuyue getByzhujian(String zhujian) {
        return caizhaiyuyueDao.getByzhujian(zhujian);
    }

    public CaizhaiyuyueVo findPage(CaizhaiyuyueVo caizhaiyuyueVo) {
        LambdaQueryWrapper<Caizhaiyuyue> wrapper = Wrappers.lambdaQuery();
		wrapper.like(ObjectUtils.isNotEmpty(caizhaiyuyueVo.getBianhao()), Caizhaiyuyue::getBianhao,caizhaiyuyueVo.getBianhao());        wrapper.like(ObjectUtils.isNotEmpty(caizhaiyuyueVo.getMingcheng()), Caizhaiyuyue::getMingcheng,caizhaiyuyueVo.getMingcheng());        wrapper.like(ObjectUtils.isNotEmpty(caizhaiyuyueVo.getZhongzhiwu()), Caizhaiyuyue::getZhongzhiwu,caizhaiyuyueVo.getZhongzhiwu());        wrapper.like(ObjectUtils.isNotEmpty(caizhaiyuyueVo.getDanjia()), Caizhaiyuyue::getDanjia,caizhaiyuyueVo.getDanjia());        wrapper.like(ObjectUtils.isNotEmpty(caizhaiyuyueVo.getYuyueriqi()), Caizhaiyuyue::getYuyueriqi,caizhaiyuyueVo.getYuyueriqi());        wrapper.like(ObjectUtils.isNotEmpty(caizhaiyuyueVo.getYuyueshiduan()), Caizhaiyuyue::getYuyueshiduan,caizhaiyuyueVo.getYuyueshiduan());        wrapper.like(ObjectUtils.isNotEmpty(caizhaiyuyueVo.getRenshu()), Caizhaiyuyue::getRenshu,caizhaiyuyueVo.getRenshu());        wrapper.like(ObjectUtils.isNotEmpty(caizhaiyuyueVo.getYonghuming()), Caizhaiyuyue::getYonghuming,caizhaiyuyueVo.getYonghuming());        wrapper.like(ObjectUtils.isNotEmpty(caizhaiyuyueVo.getXingming()), Caizhaiyuyue::getXingming,caizhaiyuyueVo.getXingming());        wrapper.like(ObjectUtils.isNotEmpty(caizhaiyuyueVo.getShouji()), Caizhaiyuyue::getShouji,caizhaiyuyueVo.getShouji());        wrapper.like(ObjectUtils.isNotEmpty(caizhaiyuyueVo.getIssh()), Caizhaiyuyue::getIssh,caizhaiyuyueVo.getIssh());        
		wrapper.orderByDesc(Caizhaiyuyue::getId);
        Page<Caizhaiyuyue> page = new Page<>(caizhaiyuyueVo.getCurrent(),caizhaiyuyueVo.getCurrentNum());
        caizhaiyuyueDao.selectPage(page,wrapper);
        List<Caizhaiyuyue> caizhaiyuyues = page.getRecords();
        caizhaiyuyueVo.setList(caizhaiyuyues);
        caizhaiyuyueVo.setPages(page.getPages());
        caizhaiyuyueVo.setTotal(page.getTotal());
        caizhaiyuyueVo.setCurrent(page.getCurrent());
        caizhaiyuyueVo.setCurrentNum(page.getSize());
        return caizhaiyuyueVo;
    }

    @Override
    public void deleteList(List<Caizhaiyuyue> list) {
        List<Integer> ids =  list.stream().map(Caizhaiyuyue::getId).collect(Collectors.toList());
        caizhaiyuyueDao.deleteBatchIds(ids);
    }
	
	
	
	
	
	//youxxianxci
}
